import java.applet.Applet;
import java.awt.Button;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class FileDialogTest extends Applet implements ActionListener {
    Frame f;
    TextArea area;

    public void init(){
        f = new Frame();
        f.setSize(300,500);
        area = new TextArea();
        f.add(area);
        Button b = new Button("OPEN");
        b.addActionListener(this);
        add(b);
    }

    public void actionPerformed(ActionEvent e){
        try {
            String line;
            String buf="";
            f.setVisible(true);
            FileDialog diag = new FileDialog(f, "Select File", FileDialog.LOAD);
            diag.setVisible(true);
            String fileName = diag.getDirectory() + diag.getFile();
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));
            while ((line = reader.readLine()) != null ){
                buf = buf + line + "\n";
            }
            area.setText(buf);
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }

    public static void main(String args[]){
        FileDialogTest fd = new FileDialogTest();
        fd.init();
        fd.setSize(500,500);
        fd.setVisible(true);
    }
}